package top.zhongyy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import top.zhongyy.pojo.Blog;
import top.zhongyy.service.ArchiveService;
import top.zhongyy.service.BlogService;

/**
 * @Created by IntelliJ IDEA.
 * @DESC:归档前端控制器
 * @Author: Andy
 * @Date: 2021/3/27
 */
@Controller
public class ArchivesShowController {
    
    @Autowired
    private ArchiveService archiveService;
    
    @Autowired
    private BlogService blogService;
    
    @GetMapping("/archives")
    public String archives(Model model) {
        model.addAttribute("archiveMap", archiveService.getArchiveBlogs());
        QueryWrapper<Blog> wrapper = new QueryWrapper<>();
        wrapper.eq("published", true);
        model.addAttribute("blogCount", blogService.count(wrapper));
        return "archives";
    }
}
